﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;

public class AudioManager : MonoBehaviour
{
    static AudioManager current;

    [Header("BGM")]
    public AudioClip 白昼音乐;
    public AudioClip 黑夜音乐;

    [Header("音效")]
    public AudioClip 融合音乐;
    public AudioClip 坐凳子音乐;
    public AudioClip 分离音乐;
    public AudioClip 震动音乐;
    public AudioClip 结束音乐;
    public AudioClip 跑步音乐;
  

    AudioSource musicSource;
    AudioSource SitClip;
    AudioSource BlendClip;
    AudioSource voiceSource;


    // Start is called before the first frame update
    void Start()
    {
        if (current != null)
        {
            Destroy(gameObject);
            return;
        }
        current = this;

        DontDestroyOnLoad(gameObject);

        musicSource = gameObject.AddComponent<AudioSource>();
        SitClip = gameObject.AddComponent<AudioSource>();
        BlendClip = gameObject.AddComponent<AudioSource>();
        voiceSource = gameObject.AddComponent<AudioSource>();

        StartLevelAudio();
    }

    void StartLevelAudio()
    {
        current.musicSource.clip = current.白昼音乐;
        current.musicSource.loop = true;
        current.musicSource.Play();
    }

    public  static void ChangeBGM()
    {
        current.musicSource.clip = current.黑夜音乐;
        current.musicSource.loop = true;
        current.musicSource.Play();
    }

    public static void BlendingAudio()
    {
        current.BlendClip.clip = current.融合音乐;
        current.BlendClip.Play();
    }

    public static void PushingAudio()
    {
        current.SitClip.clip = current.坐凳子音乐;
        if(!current.SitClip.isPlaying)
            current.SitClip.Play();
    }

    public static void PlayerStopAudio()
    {
        current.SitClip.Stop();
    }

    public static void ShakeNoise()
    {
        current.BlendClip.clip = current.震动音乐;
        current.BlendClip.Play();
    }
    public static void LampAudio()
    {
        current.voiceSource.clip = current.分离音乐;
        current.voiceSource.Play();
    }
        public static void RunAudio()
        {
            current.voiceSource.clip = current.跑步音乐;
        current.musicSource.loop = false;
        current.voiceSource.Play();
        }

        public static void EndAudio()
    {
        current.voiceSource.clip = current.结束音乐;
        current.voiceSource.Play();
    }

}
